/**
 * @a https://leetcode.cn/problems/rotate-image/submissions/656067528/
 */

#include "../common.h"

class Solution {
public:
    void rotate(vector<vector<int>>& matrix) {
        // 原地旋转
        int n = matrix.size();
        for(int i = 0; i < n / 2; ++i) // 为奇数长度的矩阵，使用行向下取整，列向上取整，由于局部性原理，效率更高
        {
            for(int j = 0; j < (n + 1) / 2; ++j){
                int tmp = matrix[i][j];
                
                matrix[i][j] = matrix[n - 1 - j][i];
                matrix[n - 1 - j][i] = matrix[n - 1 - i][n - 1 - j];
                matrix[n - 1 - i][n - 1 - j] = matrix[j][n - 1 - i];
                matrix[j][n - 1 - i] = tmp;
            }
        }
    }
};